package top.lihope.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.lihope.bean.Student;
import top.lihope.dao.StudentMapper;
import top.lihope.error.StudentException;
import top.lihope.service.StudentService;

import java.util.List;

/**
 * @description:
 * @ClassName: StudentServiceImpl
 * @author: 求求别学了，我跟不上
 * @email: xiwang.li@qq.com
 * @date： 2023/4/11 19:54
 * @version： 1.0
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> selectAll() {
        return studentMapper.selectAll();
    }

    @Transactional
    @Override
    public int insertStudent(Student student) {
        studentMapper.insertStudent(student);
        int i = 1 / 0;
        studentMapper.insertStudent(student);
        return 1;
    }

    @Override
    public int deleteById(int id) {
        try {
            int i = 1/ 0;
        }catch (Exception e){
            throw new StudentException("删除学生异常：" + e.getMessage());
        }
        return 0;
    }
}
